/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-20 07:05:14
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-20 16:33:38
 */
import 'package:flutter_data_center/model/attendance/teacher_attendance_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class TeacherAttendanceController extends GetxController {
  // 迟到
  int _late = 0;
  int get late => _late;
  // 缺卡
  int _missing = 0;
  int get missing => _missing;
  // 早退
  int _leave = 0;
  int get leave => _leave;
  // 教师列表
  List<TeacherAttendanceModel> _list = [];
  List<TeacherAttendanceModel> get list => _list;

  void getTeachersStatistics() async {
    _list = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.teachersAttendanceStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _late = data['late'];
      _missing = data['missing'];
      _leave = data['leave'];
      for (var item in data['attendances']) {
        _list.add(TeacherAttendanceModel.fromJson(item));
      }

      update();
    }
  }

  TeacherPersonAttendanceModel _detail;
  TeacherPersonAttendanceModel get detail => _detail;
  void getTeacherStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.teacherAttendanceStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _detail = TeacherPersonAttendanceModel.fromJson(data);

      update();
    }
  }

// 创建一个map
  Map<String, String> _attendanceType = {
    "late": "迟到",
    "missing": "缺卡",
    "leave": "早退"
  };
  Map<String, String> get attendanceType => _attendanceType;
}
